package edu.tjut.tjutcommunity.utils;

import edu.tjut.tjutcommunity.entity.SchoolCookie;
import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;

public class CookieUtils {


    public static String getCookieFromCookieClass(Object o) {
        Class<?> aClass = o.getClass();
        Method[] methods = aClass.getMethods();
        Field[] fields = aClass.getFields();
        String result = "";
        for (int j = 0; j < fields.length; j++) {
            String name = fields[j].getName();
            String funcName = "get" + name;
            for (Method method : methods) {
                if (funcName.equalsIgnoreCase(method.getName())) {
                    try {
                        String invoke = (String) method.invoke(o);
                        if (invoke != null) {
                            result += name + "=" + invoke + "; ";
                        }

                    } catch (IllegalAccessException | InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        return result;

    }


}
